Jump to content

Stargazers Lounge Uses Cookies

Like most websites, SGL uses cookies in order to deliver a secure, personalised service, to provide social media functions and to analyse our traffic. Continued use of SGL indicates your acceptance of our cookie policy.

sgl_imaging_challenge_banner_comet_46p.thumb.jpg.9baae12eeb853c863abc6d2cf3df5968.jpg

Gina

Water Level Gauge for the "Sump" Below my Observatory

Recommended Posts

Dug out a box to take the ultrasonic sensor and Arduino Nano - bit big but it has a seal so I can keep damp out of the electronics.  Drilled two holes in the bottom to let the ultrasonic transmitter and receiver through.  More holes will be drilled later for cables and sealed with grommets or hot melt glue which I also plan to put round the transducers for sealing.  I plan to screw the box to the noggin or joist.

post-13131-0-64678600-1452364802_thumb.jpost-13131-0-31292500-1452364804_thumb.j

Edited by Gina

Share this post


Link to post
Share on other sites

I think I've pretty much decided on the final design of the water level mearuring and display system. 

  1. The level measurement will be ultrasonic plus Arduino Nano.
  2. Data transmission will be by 1-wire bus with a DS2438 A/D chip connected to the Arduino.
  3. Display will be analogue with pointer driven by micro servo motor from Arduino.  Plus two LEDs to show pump operation.

Maybe I should go through the reasons for my decisions... 

No. 1. is the easiest and quickest method of water level measurement using just two components - an Arduino and a sensor unit. 

No. 2. May be slightly more complicated than a direct arduino to Arduino link but has expansion possibilities and I have my weather station in mind.  One extra chip and two discrete components - a resistor and a capacitor to turn a PWM output into an analogue voltage which the 1-wire chip will read. 

No 3. Again, this is the simplest and quickest solution.  Just Arduino and micro servo motor and a bit of 3D printing and colour 2D printing on paper.  The LEDs that show pump operation can simply use two wires in the CAT5 cable and with a resistor each and connect directly to the pump motors.

Edited by Gina
  • Like 2

Share this post


Link to post
Share on other sites

This project is a rather strange combination of analogue and digital data.  The water level is analogue, the sensor and Arduino turn this into a numerical value (digital) then the Arduino and a couple of discrete components chang this into an analogue voltage.  The 1-wire chip then digitises this for transmission to the display Arduino which drives a servo motor to provide and analogue dis[play.

Share this post


Link to post
Share on other sites

Here is a block diagram of the complete water level display system.

post-13131-0-41534800-1452372503_thumb.j

  • Like 1

Share this post


Link to post
Share on other sites

Now to look at changing the Arduino sketch above to send the data via 1-wire rather than by USB to a PC.

The code line that converts the ultrasonic delay time to distance in cm is :-

distance = duration/58.2;

The maximum water level is 20cm below the sensor and ground level is 40cm giving a range of 20cm.  I would like a resolution better than 1 in 20 so the conversion could be to distance in mm by changing the code to :-

distance = duration/5.82;

Then we can apply an offset so that the ground level corresponds to 200mm and maximum level to zero by subtracting 200 viz.

distance = (duration/5.82) - 200.0;

To drive the DS2438 a PWM digital output is used followed by smoothing to a steady analogue voltage.  This is achieved using the analogWrite()

command which converts a numerical value of 0-255 to an effective voltage of 0-5v.  To make best use of the range it would make sense to make the water level reading in the 0-255 range rather than 0-199.  To do this simply means altering the divisor for the duration to distance conversion code.  ie. to use 256 values instead of 200 the divisor of 5.82 changes to 5.82 x 200 / 256 = 4.55 so the code becomes :-

distance = (duration/4.55) - 256.0;

Then instead of sending this value to the Serial Monitor we send it to a PWM output viz.

analogWrite(outPin, distance);

Where outPin has been defined as the pin connected to the RC network driving the DS2438.

From other projects involving the DS2438 the series resistor can be 100K and the capacitor can be used not only to smooth the PWM but also as an averaging device to cope with waves on the water causing varying distance readings.  Seems to me a time constant of around a second should be fine. So...

C = T / R = 1 / 100,000 Farads = 10 microFarads.  An electrolytic capacitor will be fine.

That covers modification to the Arduino sketch above to send the water level data over the 1-wire bus instead of to a PC.  I'll post the full modified sketch tomorrow.  I'm finishing for the night now.  Nighty night everyone :)

Edited by Gina
  • Like 2

Share this post


Link to post
Share on other sites

Here is the complete Arduino sketch for the transmitting end.  Tested using the Serial Monitor on living room carpet :D  I shall try it with water later and also put a voltmeter on the PWM output.  Currently using Arduino UNO for test rig.

/* File name :- HC-SR04_Ping_distance_sensor_DS2438_01 -- saved 2016-01-10 1115 Gina mods to use DS2438 1-wire device.  Serial Monitor code retained for testing. HC-SR04 Ping distance sensor: VCC to arduino 5v  GND to arduino GND Echo to Arduino pin 7  Trig to Arduino pin 8  This sketch originates from Virtualmix: http://goo.gl/kJ8Gl Has been modified by Winkle ink here: http://winkleink.blogspot.com.au/2012/05/arduino-hc-sr04-ultrasonic-distance.html And modified further by ScottC here: http://arduinobasics.blogspot.com.au/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html on 10 Nov 2012. Adopted and modified to use DS2438 1-wire device for remote display of water level. 10 Jan 2016. */#define echoPin 7 // Echo Pin#define trigPin 8 // Trigger Pin#define LEDPin 13 // Onboard LED#define outPin 3  // Ouput Pinint maximumRange = 300; // Maximum range neededint minimumRange = 0; // Minimum range neededlong duration, distance; // Duration used to calculate distancevoid setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(LEDPin, OUTPUT); // Use LED indicator (if required) pinMode(outPin, OUTPUT); // PWM Output to DS2438}void loop() {/* The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it. */  digitalWrite(trigPin, LOW);  delayMicroseconds(2);  digitalWrite(trigPin, HIGH); delayMicroseconds(10);   digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH);  //Calculate the distance (in cm) based on the speed of sound. distance = (duration/4.55) - 256.0;  // Gina mod for DS2438  if (distance >= maximumRange || distance <= minimumRange){ /* Send a negative number to computer and Turn LED ON  to indicate "out of range" */ Serial.println("-1"); digitalWrite(LEDPin, HIGH);  } else { /* Send the distance to the computer using Serial protocol, and turn LED OFF to indicate successful reading. */ Serial.println(distance); digitalWrite(LEDPin, LOW); analogWrite(outPin, distance);  }  //Delay 50ms before next reading. delay(50);}

Share this post


Link to post
Share on other sites

Here is an updated block diagram showing the 1-wire feed and terminating resistors plus conponent values etc.

post-13131-0-63912000-1452432525_thumb.j

Share this post


Link to post
Share on other sites

Interesting thread to follow, goes over my head but what you don't expose yourself to can never be learnt.

Edited by happy-kat
  • Like 1

Share this post


Link to post
Share on other sites

Or you could use an pair f RS232 converter chips back to back. As these generate a ~15V signal they are very robust over long distances.

Share this post


Link to post
Share on other sites

There's not a lot more I can do to this until some parts arrive - expected Tuesday.  I've checked that the sensor reads water level rather than the bottom of the vessel using a bowl on the floor and adding water to it.  It also doesn't mind small waves.  I could check that the Arduino outputs the PWM correctly but I can't see why not.

Share this post


Link to post
Share on other sites

Or you could use an pair f RS232 converter chips back to back. As these generate a ~15V signal they are very robust over long distances.

Wouldn't that need a 15v supply?  Anyway, I know 1-wire works and I'm familiar with it.  Also, it's a multi-device bus that you can add virtually any amount to.  So thanks for the idea but I think I'll stick with 1-wire.

Share this post


Link to post
Share on other sites

Wouldn't that need a 15v supply?  Anyway, I know 1-wire works and I'm familiar with it.  Also, it's a multi-device bus that you can add virtually any amount to.  So thanks for the idea but I think I'll stick with 1-wire.

They have built in voltage mutipliers/polarity reversers. Damn clever little blighters.

I discovered the MAX232 when I blew up the RS423 in my BBC B. :icon_albino:

Wasn't it nice when computers came with circuit diagrams you could actually use to fix them!

  • Like 2

Share this post


Link to post
Share on other sites

I used to have a BBC B and loved it :)  May still have it - lurking somewhere in the loft :D  Amongst other things I wrote word processor software for it using a special narrow font I devised to get more characters along the line - written directly in assembler :)  Yes, I did several hardware mods to it too, adding extra memory etc.  Great fun.  Now my fun is with Arduinos :D  But the C language is a lot easier than assembler.

Edited by Gina
  • Like 1

Share this post


Link to post
Share on other sites

Some bits have arrived torards the water level sensor unit but crucially not the DS2438 chips.  Got the SMD to DIP 8pin PCBs but not the chips.  Also more Arduino Nanos and micro servo motors.  May have a change of plan for the Arduino to 1-wire interface though as I posted in the instrumentation thread - DS2408 8 bit PIO chips, providing a digital multi-bit interface.  PIO = Programmable Input/Output meaning that the pins can be programmed for either input or output.

Amazingly, the DS2408 chips I ordered from RS Components yesterday evening have just arrived by Parcel Force :)  Now that's what I call fast delivery :D  I have SMD to DIP 16pin PCBs on order for them due to arrive Thursday or Friday.

Share this post


Link to post
Share on other sites

I have just checked the chip on the image I posted with a magnifying glass and it is a DS2408. I think I was going to build some sort of analogue output display or alarm for my weather station but never got round to it :icon_sad:

  • Like 1

Share this post


Link to post
Share on other sites

I used to have a BBC B and loved it :)  May still have it - lurking somewhere in the loft :D  Amongst other things I wrote word processor software for it using a special narrow font I devised to get more characters along the line - written directly in assembler :)  Yes, I did several hardware mods to it too, adding extra memory etc.  Great fun.  Now my fun is with Arduinos :D  But the C language is a lot easier than assembler.

When I was at the Beeb we used to get the new models & accessories into the workshop for testing prior to general release. Great for games on night shifts :grin:

I seem to remember Elite and Planetoid (a 'Defender' clone) were firm favourites.

  • Like 2

Share this post


Link to post
Share on other sites

Great to hear more stories of how the BEEB got people into 'real' computing.

A beeb would make a great central hub for lots of projects, I'm sure it would be able to run a goto mount.

I have Elite somewhere. PI could never last more than 20 seconds at Planetoid.

I wish someone would come out with a BBC micro in laptop form, just for the hell of it. Much better for learning programming than an Rpi.

I've made my own prototypes - info on the display part here.

  • Like 1

Share this post


Link to post
Share on other sites

Not having SGL to post on hasn't stopped me from thinking, taking a step back and taking an overall view of my projects - this one in particular.  I'm back in this thread because I am separating the water level gauge from the overall observatory instrumentation which includes a lot of the weather station stuff and is currently based on the 1-wire DS2408 which I'm struggling with.  I have had to shelve that issue as it was doing my head in!!

Just taking the water level gauge on it's own, the remarkably obvious solution of the communication from obsy to house completely evaded me.  But not now haha.  Earlier in this thread I was looking at changing the 256 possible levels into PWM and then smoothed to an analogue voltage to be read by a 1-wire A/D but I could send a DC voltage directly over the wires and read it indoors with an analogue input on the Arduino - or even drive a large analogue meter :icon_rolleyes:

I have now received the little pump and tried it out indoors - seems alright - much smaller throughput of course.  This diagram shows the new comms and the little 12v pump driven from the main observatory power supply with a 5v relay from a digital pin on the Arduino Nano.  The 100K resistor on D5 removes any line loading from the Arduino and in conjunction with the 10μF capacitor at the other end of the cable, smooths both the PWM and the variations of level reading due to small waves on the water surface.  It should also effectively remove all interference that might be picked up by the cable.

56a4c8abcd8ef_Wiringdiagram06.thumb.JPG.

  • Like 2

Share this post


Link to post
Share on other sites

Here are some photos of the water level control unit and smaller pump.

Pump with output hose and 3D printed filter on inlet to keep muck out.  Pump cable is glued in and sealed with hot melt glue.  The relay is fixed down with it too.  I was going to put the relay on strip board but the lead spacings don't fit - they aren't on a 0.1" grid.

56a5251e34a5d_WaterLevelControlUnit045.t56a5251a7ead3_WaterLevelControlUnit04.th

Underside of box showing ultrasonic transmitter and receiver glued and sealed with hot melt glue.  The pump cable is also sealed in the same way.

56a525170bfeb_WaterLevelControlUnit03.th56a52512e5c5d_WaterLevelControlUnit02.th56a5250fde395_WaterLevelControlUnit01.th

Edited by Gina
  • Like 1

Share this post


Link to post
Share on other sites

Here is the sketch to run the observatory unit.  I had thought of using the EEPROM to store the little pump start and stop levels but these should only need setting up once so EEPROM would have been overkill.  I have decided I can set these using the laptop plugged into the USB port and using the Arduino IDE editor.  The laptop will also report on what's happening.  I may need to run a hosepipe from the shed to the sump to test operation.  Can't actually rely on the rain haha.

/*
 File name :- HC-SR04_Ping_distance_sensor_mm_for_little_pump_02    2016-01-24 2020
 Test sketch sending output string to Serial Monitor.  Range 100-500 with 000 indicating error (out of range)
 Multiple readings taken to get average over 10 cycles
 Little pump is started and stopped at levels given by pumpStart and pumpStop on line 28.  Relative to bottom of control unit.
 Use editor to adjust these if required, recompile and upload.
 
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v 
 GND to arduino GND
 Trig to Arduino pin 8
 Echo to Arduino pin 9 
 
 This sketch originates from Virtualmix: http://goo.gl/kJ8Gl
 Has been modified by Winkle ink here: http://winkleink.blogspot.com.au/2012/05/arduino-hc-sr04-ultrasonic-distance.html
 And modified further by ScottC here: http://arduinobasics.blogspot.com.au/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html
 on 10 Nov 2012.
 Adopted and modified by Gina January 2016.
 */
#define trigPin 3 // Trigger Pin
#define echoPin 2 // Echo Pin
#define LEDPin 13 // Onboard LED

int maximumRange = 500; // Maximum range needed
int minimumRange = 100; // Minimum range needed
long duration, distance; // Duration used to calculate distance
int cycles = 10; // Number of cycles of ping to accumulate average duration
int pumpStart = 450, pumpStop = 475;
boolean pumpRunning = false;

void setup() {
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}
//
void accumulateDuration() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */ 
 digitalWrite(trigPin, LOW); 
 delayMicroseconds(2); 
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 
 digitalWrite(trigPin, LOW);
 duration = duration + pulseIn(echoPin, HIGH);
 //Delay 50ms before next reading.
 delay(50);
}
void loop() {
  duration = 0;
 for (int c = 0; c < cycles; c++) { accumulateDuration(); }
 duration = duration / cycles;
 //Calculate the distance (in mm) based on the speed of sound.
 distance = duration/5.82;

 if (distance >= maximumRange || distance <= minimumRange){
 /* Send a negative number to computer and Turn LED ON 
 to indicate "out of range" */
 Serial.println("000");
 }
 else {
  if ((distance < pumpStart) && !pumpRunning) { pumpRunning = true; Serial.println("Pump Started"); }
  if ((distance > pumpStop) && pumpRunning) { pumpRunning = false; Serial.println("Pump Stopped"); }
  digitalWrite(LEDPin, pumpRunning); 
/* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 Serial.println(String(distance, DEC));
 analogWrite(5, distance);
 }
 
}

 

Share this post


Link to post
Share on other sites

Well, the code above had colour earlier, rather muted but colour none the less.  Now it's gone.  I presume upgarding is still going on so I won't pass comment.

Share this post


Link to post
Share on other sites

The more you post the more I want a 3D printer... I've just realised I could print a body for a finderscope I'm building, complete with baffles.

  • Like 1

Share this post


Link to post
Share on other sites
53 minutes ago, fireshipjohn said:

Hi Gina,

Of course when you complete this project it will guarantee no rain for at least 8 weeks :)

John

So hurry up!

;-)

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.