This sketch shows how to use the most important features of the 4-20mA current loop board in Waspmote. This standard is used to transmit information of sensor over long distances. Waspmote uses analog inputs for reading the sensor values.
Required Materials
1 x Waspmote
1 x Battery
1 x 4-20 mA Board
Notes
- Don't use the 12 V output to supply industrial devices, only for 4-20 mA sensors. - Be sure that your sensor is compatible with the 4-20 mA board specifications.
- This example can be executed in Waspmote v12 and Waspmote v15
Code
/* * ------ [4-20mA_01] Current Loop Basic Example -------- * * Explanation: This sketch shows how to use the most important * features of the 4-20mA current loop board in Waspmote. This * standard is used to transmit information of sensor over long * distances. Waspmote uses analog inputs for reading the sensor * values. * * Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Version: 3.0 * Design: David Gascon * Implementation: Ahmad Saad */// Include this library for using current loop functions#include<currentLoop.h>voidsetup(){// Power on the USB for viewing data in the serial monitorUSB.ON();delay(100); // Sets the 5V switch ONcurrentLoopBoard.ON(SUPPLY5V);delay(1000);// Sets the 12V switch ONcurrentLoopBoard.ON(SUPPLY12V); delay(1000); }voidloop(){ // Get the sensor value in integer format (0-1023)int value =currentLoopBoard.readChannel(CHANNEL1); USB.print("Int value read from channel 1: ");USB.println(value);// Get the sensor value as a voltage in Voltsfloat voltage =currentLoopBoard.readVoltage(CHANNEL1); USB.print("Voltage value rad from channel 1: ");USB.print(voltage);USB.println("V");// Get the sensor value as a current in mAfloat current =currentLoopBoard.readCurrent(CHANNEL1);USB.print("Current value read from channel 1: ");USB.print(current);USB.println("mA");USB.println("***************************************");USB.print("\n");delay(1000);}
Output
H#
Int value read from channel 1: 131
Voltage value rad from channel 1: 1.3612903356V
Current value read from channel 1: 7.4291305541mA
***************************************