Friday, October 9, 2015

Arduino Flood Level Monitor

Since half of South Carolina is under water, and the levels keep increasing each day, I decided to modify our fuel and cistern fluid level project to a flood level monitor. We start with a eTape level sensor from Milone Technologies. You could connect this to a ethernet or wifi shield, or even a gsm shield to notify you of water levels.

Their website lists up to 32", but longer units are available.


Connect to an available analog input. Different length sensors have different resistance values which we will enable in the code.

So, with pin 1 to +5, pin 2 to Gnd, and pins 3 & 4 to Arduino analog in:

int sensorPin = 0; // select the analog input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
float h; // variable for height of liquid

void setup() {
Serial.begin(9600);
}

void loop() {
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue); //actual adc value
Serial.println(" ADC");

// Uncomment one of the lines below to match your sensor
//h = mapfloat(sensorValue, 215, 512, 8, 0) //8"
h = mapfloat(sensorValue, 170, 512, 12, 0); //12"
//h = mapfloat(sensorValue, 93, 512, 24, 0); //24"
//h = mapfloat(sensorValue, 75, 512, 32, 0); //32"

Serial.print(h, 2); // fluid height (inches)
Serial.println(" inches");
delay(5000); //how long between measurements
 }

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max){
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Monday, October 5, 2015

Simple Seven Segment LED Displays

Seven Segment LED's are a common method of displaying data. With 8 datapins, they are also complicated to wire up, as each LED needs a Arduino pin and a resistor. With a library, we can simplify the wiring, and the data display. Typical displays look like the following:

To reduce the number of Arduino connections if we want to use multiple digits, we will connect all the a segments together, all the b segments together, all the c segments, and so on. We will have a data line for each common so we can light up each segment with different data.

So here goes, connect a 330 ohm resistor to Arduino pin 2. then connect the other end of that resistor to segment a on each module. Follow the chart for the other pins.

Arduino pin 2 -> 330 ohm resistor -> all segment a's
Arduino pin 3 -> 330 ohm resistor -> all segment b's
Arduino pin 4 -> 330 ohm resistor -> all segment c's
Arduino pin 5 -> 330 ohm resistor -> all segment d's
Arduino pin 6 -> 330 ohm resistor -> all segment e's
Arduino pin 7 -> 330 ohm resistor -> all segment f's
Arduino pin 8 -> 330 ohm resistor -> all segment g's
Arduino pin 9 -> 330 ohm resistor -> all segment p's (decimal Point)

1st module com to Arduino pin 10
2nd module com to Arduino pin 11
etc.


You will need to download and install the library from https://github.com/DeanIsMe/SevSeg

Now the code:



#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object


void setup() {
  Serial.begin(9600);
  
  byte numDigits = 2;   // number of modules
  byte digitPins[] = {10,11}; // where your common pins are connected
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; //where your segments pins are connected

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); //Use COMMON_CATHODE if your modules use gnd on the common, or COMMON_ANODE if they take positive on the common.
  sevseg.setBrightness(90);
}

void loop() {
  
  int d1 = 12; // number you want displayed, usually from a sensor
  sevseg.setNumber(d1, 1); //display number, with optional decimal point (1 place)

  sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///

More info at http://playground.arduino.cc/Main/SevenSegmentLibrary