How To Use Our Product Lines
How to use SCALAE - IOT
8min
introduction scalae wifi switch docid 5duzumrqti2rkhu x6xgc or scalae iot is one of our versatile products that can be programmed to accomplish different tasks as needed the hardware is arranged for a monitoring application with the ability to actuate autonomously and then provide reporting and feedback along with the option for remote control and monitoring the product falls into our automate | connect | control philosophy this application will introduce the product's features and then step you through a basic application of measuring the analog value of a moisture sensor features the following features give the scalae iot some punch when used in a field application and enable it to perform a number of tasks effectively specifications wifi switch device pic microcontroller pic18f2xkxx soic family device usb connectivity yes for system configuration local data logging device programming icsp | usart bootloader power supply onboard psu, optimized for low power operation io reset button, opto isolated inputs, relay output temperature sensors dallas 1 wire (ruggardised), lm35 , dht 11 communication wifi esp8266 , optional module usb uart ch340g these sensors or modules are recommended or have been tested with the scalae iot overview this project example will demonstrate integrating a soil moisture sensor this will include how to connect the sensor and then read and interpret the reading implementation to get started, your shopping list is the following scalae iot soil moisture sensor (seed studio) jumpers power supply dry soil + jug of water to code the code has been written using mikroc docid\ kklyqtdvggo78eel 4aci , which is a c centric compiler the compiler is a very useful coding environment as it also includes many integrated libraries the code does the following configure the hardware read the sensor process the reading report the value / scalae iot dev version october 2024 device pic18f25k22 / // declarations \#define an 1 char ver ="node v dev"; char uart rd; char soilmoisvalu ="0000"; char soilmoistest="0000"; unsigned short adc channel; unsigned temp; int i; // functions void setupsystem(void); void cr(); char soilmoisture(unsigned short channel); // code void cr(){ uart1 write(10); uart1 write(13); delay ms(10); } char soilmoisture(unsigned short channel){ char temp = "0000"; unsigned int adc value; adc value = adc read(channel); delay ms(10); temp\[0] = adc value/1000 + 48; // add 48 to get the ascii character value temp\[1] = ( adc value/100)%10 + 48; temp\[2] = ( adc value/10)%10 + 48; temp\[3] = adc value%10 + 48; return temp; } void setupsystem(void){ / analog configuration / ansela = 0b00000010; // configure an pins as digital anselb = 0; anselc = 0; / ports configuration / trisa = 0b00000010;; trisb = 0; trisc = 0; c1on bit = 0; // disable comparators c2on bit = 0; / uart communications / uart1 init(9600); // initialize uart module at 9600 bps delay ms(100); // wait for uart module to stabilize uart1 write text(ver); cr(); } void main() { setupsystem(); while(1){ if (uart1 data ready()) { // if data is received, uart rd = uart1 read(); // read the received data, switch (uart rd){ case'a' uart1 write('a');break; case'v' uart1 write text(ver);break; default uart1 write(uart rd); // and send data via uart } } soilmoisvalu = soilmoisture(an); delay ms(10); uart1 write text(soilmoisvalu); delay ms(1000); cr(); } } what the code does the code accomplishes key tasks that are required to set up the hardware, then for the module to repeatedly and reliably perform the task of processing and reporting the value the function setupsystem() is tasked with configuring the mcu for this application, the device is setup mainly for "safe" operation to prevent any spurious actions taking place for this reason, all i/o are set to inputs and this prevents the relay from actuating for example this then brings us back to the void main() that calls the setupsystem() function and then once in the while(1) loop, then calls, at this point the main working function the soilmoisture() function takes in the parameter for the analog channel that would be used this is to accommodate any future changes where an alternative channel may be used the mikroc provides a library for reading the analog inputs, with the only input parameter required being the channel this is passed in, and the value is returned once the a2d module has performed the calculation, you have a large number that needs to be processed firstly a value that can be reported using an lcd or usart and secondly, a format that can be interpreted and used this is performed within the function, converting it to a char which can be exported using the usart you can also a lcd display as the value is compatible type to view the value being reported, you can use the coms terminal available from within mikroc it is located here tools > usart terminal as noted in the values reported, a high value indicates drier soil and a lower value more moist soil what is next? in the next installment, we will consider how to use the value that was read and what actions that can be take