[TOC]
This guide introduces the WisBlock IO RAK5811 0-5V board features and explains how to program with it.
The reference voltage of the ADC in the RAK4631 is 3.0 volts, so this is the maximum voltage that the RAK4631 can measure. In order to expand the measurement range to 0-5 volts, the RAK5801 module reduces the voltage signal to be measured to the range of 0-3.0 volts.
The conversion formula is as follows:
Note: Please refer to the schematic for details of the conversion method.
To build this system the WisBlock Core RAK4631 microcontroller is using the RAK5811 module. With just two WisBlock plugged into the WisBlock Base RAK5005-O board the system is ready to be used.
- WisBlock Base RAK5005-O
- WisBlock Core RAK4631
- WisBlock IO RAK5811
- Output voltage max: +12 V
- Temperature Range: [-40 °C, 125 °C]
The Module includes a 12 V power which is controled by RAK4631,GPIO 0.17. This GPIO must be set to HIGH before sampling. The power also can be used as power supply for sensors. The majority of sensor works in the 9-24 V range. Before connecting a sensor to the 0-5V module, you must be sure that 12 V fits the sensor’s range of the power supply.
{
/*
* WisIO RAK5801 Power On
*/
pinMode(17, OUTPUT);
digitalWrite(17, HIGH);
}
{
int sensor_pin = A1;
int result;
result = analogRead(sensor_pin);
}
{
voltage_ain = result * 3.0 /1024; //Reference voltage 3.0v / 10bit ADC
voltage_sensor = voltage_ain/0.6; //WisBlock RAK5811 (0 ~ 5V). Input signal reduced to 6/10 and output
}
#include <Arduino.h>
#define ULB6_SENSOR
void setup()
{
/*
* WisBLOCK 5811 Power On
*/
pinMode(17, OUTPUT);
digitalWrite(17, HIGH);
pinMode(A1, INPUT_PULLDOWN);
analogReference(AR_INTERNAL_3_0);
analogOversampling(128);
// Initialize Serial for debug output
Serial.begin(115200);
while(!Serial){delay(10);}
}
void loop()
{
int i;
int sensor_pin = A1; // the input pin A1 for the potentiometer
int mcu_ain_value = 0;
int depths; // variable to store the value of oil depths
int average_value;
float voltage_ain;
float voltage_sensor; // variable to store the value coming from the sensor
for (i = 0; i < 5; i++)
{
mcu_ain_value += analogRead(sensor_pin);
}
average_value = mcu_ain_value / i;
voltage_ain = average_value * 3.0 /1024; //raef 3.0v / 10bit ADC
voltage_sensor = voltage_ain/0.6; //WisBlock RAK5811 (0 ~ 5V). Input signal reduced to 6/10 and output
depths = (voltage_sensor*1000 - 574)*2.5; //Convert to millivolt. 574mv is the default output from sensor
Serial.printf("-------average_value------ = %d\n", average_value);
Serial.printf("-------voltage_sensor------ = %f\n", voltage_sensor);
Serial.printf("-------depths------ = %d mm\n", depths);
delay(2000);
}