Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: AnalogRead() for my flex sensor only gives 1023 on: February 22, 2014, 08:08:40 am
Instead of this,
Code:
  digitalWrite(flexpin,HIGH);
  digitalWrite(softpotpin, HIGH);
  digitalWrite(potPin,HIGH);

try this,

Code:
  pinMode(flexpin,INPUT);
  pinMode(softpotpin, INPUT);
  pinMode(potPin,INPUT);

Not sure why your are writing a high value to pins that you are using for analog inputs.


Also like some others said is to first check the voltage going to the pin directly with a multimeter to rule out hardware issues.
2  Using Arduino / Programming Questions / Re: Feasibility of a temperature gauge on: February 20, 2014, 03:10:46 pm
So you want the servo to move back and forth based on a temperature reading that is always changing?
3  Using Arduino / Programming Questions / Re: aquarium light controller on: February 20, 2014, 12:51:54 pm
Code looks great! If it works well, I'd say youre 99% there. The rest is tweaks. Try adding an LCD shield such as :
http://www.adafruit.com/products/772

That would allow you to make some menus to scroll thru to set different parameters and show them.

Take a look at my thermostat code. Its very similar:

http://pastebin.com/YxKFUr2y



I did have LCD code in there before for diagnostic purposes, but have since taken it all out. I do see some sort of LCD option with a meny system in the future for on the fly adjustments though.
4  Using Arduino / Programming Questions / Re: A little bit of code help needed *Warning I'm A Noob* on: February 20, 2014, 12:47:38 pm
I'm working on a arduino based light controller for an aquarium as well. Didn't see this thread until after I posted a new thread.

While my method for getting the lights on and off are different than yours, my code may offer some help.

I have implemented fading on the lights, lighting schedule, manual override,  sunrise/sunset timing, and power loss recovery. You may be able to implement some of the code for your needs.

http://forum.arduino.cc/index.php?topic=219680.0
5  Using Arduino / Programming Questions / aquarium light controller on: February 20, 2014, 12:34:43 pm
So I'm building an aquarium light controller for a family member. Now while I've done lots of smaller projects for myself, I've never worked on a project that's intended to run 24/7. The application is for controlling DIY LED lights.The LED's use a constant current power supply that is adjustable via 0-10V input. 

So I built a shield that uses one of the PWM outputs, runs it through a simple RC filter circuit and an opamp to achieve 0-10V. There is a button to provide a manual override of the lights and an RTC module to provide time for the lighting schedule.

Through software I've implemented adjustable sunrise/sunset timing, the lighting schedule, brightness control, manual override, and a soft start feature for the LED when going in and out of manual override mode. I consider myself an amateur with very little programming experience. So I'd like to post the code that I've come up with (which through all my testing works as intended) in order to have some of you who are more experience comment on it.

I'm looking to see if I could have done things different, or more efficient, or used better coding/programming conventions. While this sketch is small, it needs to run reliably 24/7. And I'm thinking if I learn better coding skills now, it'll help in the long run with larger, more complicated sketches. I've done my best to comment as much as possible to show what the code does.

Thanks in advance for any hints, tips, help, or criticism you may provide.

Code:
/* Aquarium Light Controller

Written by John Dimo

Sets turn on time, turn off time, power loss failsafe, adjustable sunset/sunrise
times, smooth fading LED on/off, override button, max brightness control,etc.

Arduino Pin 6 is the output for lights.
Arduino Pin 12 is for the override button.
Arduino Pins A0 and A1 are for the RTC module.

Version 1.0 - Initial Version. Basic light timer, with adjustable
              ramp up/down and total running time.
Version 1.1 - Added code for LCD display to show diagnostic messages.
Version 1.2 - Added adjustable max brightness control.
Version 1.3 - Removed all the delays so that code can loop through and do other
              stuff during sunrise and sunset timing code.
Version 1.4 - Added Override Button to turn lights on and off.
Version 1.5 - Added RTC module. Now has daily adjustable start time.
Version 1.6 - Added alarm for daily adjustable off time. Added failsafe to restart
              lights in the event of power loss.
Version 1.7 - Added smooth on/off for the lights when using override button or
              when recovering from power loss.

*////////////////////////////////////////////////////////////////////
// user adjustable timing
int rampTime = 10; //Time in minutes to turn on/off the lights
int maxBrightness = 75; //Brightness in percentage
byte alarmOn[] = {8, 15}; // set the hour and minutes to start and stop the
byte alarmOff[] = {15, 15}; // timer, must use 24 hour time format
//////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////
/////// Change nothing below here !!! ////////////////////////////
//////////////////////////////////////////////////////////////////
#include <Time.h> 
#include <Wire.h> 
#include <DS1307RTC.h>

// global variables
int stage = 0; // set initial timing stage
int buttonState;
int lastbuttonState = HIGH;
unsigned long oldButtontime = 0;
unsigned long oldRamptime = 0;
int lightOutput = 0;
int lightSetpoint = 0;
int overridelights = LOW;

//setup loop
void setup() {
 
  ///////////////////////////////
  // Seteup some pins to power the RTC. Will not be needed when building the board
  pinMode(A3, OUTPUT);
  digitalWrite(A3, HIGH);
  pinMode(A2, OUTPUT);
  digitalWrite(A2, LOW);
  ////////////////////////////////////////////
 
  setSyncProvider(RTC.get); // tell code to get the time from RTC
  pinMode(6, OUTPUT); //setup the output pin
  pinMode(12, INPUT); // setup the input button
  pinMode(13, OUTPUT); //temp diagnostic LED
  maxBrightness = map(maxBrightness,0,100,0,255); // Map percentage to output range.
  rampTime = rampTime * 60000 / maxBrightness; // Setup ramptime delay based on max brightness setting
 
  //setup fail safe to restart lights during lights ON stage.
  if (word(hour(), minute()) >= word(alarmOn[0],alarmOn[1])) {
    if (word(hour(), minute()) <= word(alarmOff[0],alarmOff[1])){
      lightSetpoint = maxBrightness;
      stage = 2;
    }
  }
}

//main program loop
void loop() {
  unsigned long currentTime = millis(); //set current time
 
  //override button code. ignores if you hold button down. handles hardware debounce
  int reading = digitalRead(12);
  if (reading != lastbuttonState) {
    oldButtontime = currentTime;
  }
  if (currentTime - oldButtontime > 50) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == LOW) {
        //This is the part of code that does something when button is pressed
        overridelights = !overridelights; // toggle the override
      }
    }
  }
  lastbuttonState = reading; // update the state of the button
 
  //Diagnostic LED to if we're in manual override mode or not.
  if (overridelights == HIGH) digitalWrite(13, HIGH);
  if (overridelights == LOW) digitalWrite(13, LOW);
 
  // Stage 0. Waiting for alarm that starts lighting cycle
  if (stage == 0 && (hour() == alarmOn[0]) && (minute() == alarmOn[1])) stage = 1;
   
  // Stage 1. Sunrise Code.
  if (stage == 1 && currentTime - oldRamptime > rampTime) {
    oldRamptime = currentTime;
    lightSetpoint++;
    if (lightSetpoint == maxBrightness) stage = 2;
  }
 
  // Stage 2. Waiting for alarm that stops lighting cycle.
  if (stage == 2 && (hour() == alarmOff[0]) && (minute() == alarmOff[1])) {
    stage = 3;
  }
 
  // Stage 3. Sunset Code.
  if (stage == 3 && currentTime - oldRamptime > rampTime) {
    oldRamptime = currentTime;
    lightSetpoint--;
    if (lightSetpoint == 0) stage = 0;
  }
 
  //During lights ON stages, override turns off lights
  if (stage != 0 && overridelights == HIGH) {
    for(lightOutput; lightOutput >= 0; lightOutput--) {
      analogWrite(6, lightOutput);
      delay(4);
    }
    lightOutput = 0;
  }
 
  //During lights ON stages, set lights to current setpoint
  if (stage != 0 && overridelights == LOW) {
    if(lightOutput < lightSetpoint) {
      for(lightOutput; lightOutput <= lightSetpoint; lightOutput++) {
        analogWrite(6, lightOutput);
        delay(4);
      }
    }
    if(lightOutput > lightSetpoint) {
      for(lightOutput; lightOutput >= lightSetpoint; lightOutput--) {
        analogWrite(6, lightOutput);
        delay(4);
      }
    }
  }
 
  // During lights OFF stage, overries will turn on the lights.
  if (stage == 0 && overridelights == HIGH) {
    for(lightOutput; lightOutput <= maxBrightness; lightOutput++) {
      analogWrite(6, lightOutput);
      delay(4);
    }
  }
 
  // During lights OFF stage, turn off lights.
  if (stage == 0 && overridelights == LOW) {
    for(lightOutput; lightOutput >= 0; lightOutput--) {
      analogWrite(6, lightOutput);
      delay(4);
    }
    lightOutput = 0;
  }
}
6  Using Arduino / Programming Questions / Re: Loading sketch to Arduino without bootloader on: December 21, 2011, 03:03:18 pm
I did a write up on this a while back.

Here you go, http://www.johndimo.com/2011/05/06/how-to-program-your-arduino-uno-with-an-avr-isp-mkii/

7  Community / Exhibition / Gallery / My take on an Arduino based digital thermometer on: February 25, 2011, 12:54:54 pm
This is my first project I put together in an effort to learn more about the Arduino platform. It's a digital thermometer that with an external connector to the DS18B20 temp sensor. The first sensor I built keeps the sensor close to give me ambient temps and I'm currently building 2 others. One with long wires that I can place just further away and one that is waterproof so I can measure liquid temps.

I'd have to say, I'm really liking the speed of prototyping that the Arduino platform offers me.

http://www.johndimo.com/2011/02/25/diy-arduino-based-digital-thermometer/
8  Using Arduino / General Electronics / Re: Splitting an Opto-Coupled Connection on: February 04, 2011, 10:03:27 pm
You are missing limiting resistors. You'll blow the led's on the optos in the targeted device without them.
9  Using Arduino / General Electronics / Re: No pin markings... on: February 03, 2011, 03:24:52 pm
You are a genius smiley-grin

Why dont they put this kind of thing in the datasheets, thankfully I had put it on correctly first time.  Just need to test now.

Thanks!

No problem. Good luck with the testing! Hope all goes good.
10  Using Arduino / General Electronics / Re: No pin markings... on: February 03, 2011, 12:56:30 pm
I've seen lots of SOIC parts that have no painted markings or a dimple on one end on them to denote where pin 1 is.

Look at the plastic body. Look and see if one entire side of it is shaved at a 45 angle.

Typically with parts like this, one side of the chip will be a standard 90 degree, the other at around 45 degree.  The side with the angle in it is how you can tell what it is.
Look at the pic below. See the offset in the marking? That's because of the angle in the body. The marking is centered on the flat area.  The leftmost pin on the side with the angle is pin 1.



11  Using Arduino / General Electronics / Re: digital multimeter on: February 02, 2011, 10:03:15 pm
The most important lesson for beginners to understand about using digital multi-meters is the danger of attempting to measure a voltage if the meter leads/function are setup in current measurement mode. A current must be measured with the meter leads in series while a voltage is measured in parallel.

A meter in current mode is in effect a direct short circuit (at least up to it's 10amp protection fuse, if it has a fuse) between the measurement leads and if you have a brain fart and attempt to measure a voltage it can cause damage to the circuit you are trying to measure. Some meters have a warning beeper if function is voltage but leads are in current mode.

Lefty
 

I've been working with electronics for 13 years and to this day every once in a while I have done exactly this! I'm always extra careful at work, but sometimes I overlook the simplest things. One time while measuring a 700vdc DC bus voltage I mistakenly unplugged the wires from my meter instead of the voltage source. Gave myself a shock that I'll never forget. My hand was shaking for hours after.

Let this be a warning to people. Please always double and triple check what you are doing, for your safety and the safety of the electronics you're working with.
12  Using Arduino / General Electronics / Re: Wrong labeled resistors? on: February 02, 2011, 09:49:40 pm
A quick way to check the resistance on a resistor that low of value is to first measure the resistor. Then short out your leads to measure the resistance in the leads (most affordable leads will read .3 to .5 on a good meter). Subtract the resistance of your leads from the value you read when you measured the resistor.

Also, remember the tolerance of 5%. For a 3.9 ohm resistor, the value can be anywhere from 3.7 ohms to 4.1 ohms.
13  Using Arduino / Sensors / Anyone have experience using these PIR motion sensors? on: January 31, 2011, 03:53:11 pm
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=255-2649-ND

Here is the datasheet for these, http://pewa.panasonic.com/assets/pcsd/catalog/napion-catalog.pdf

Curious about these. I like the size of it and that all the circuitry is internal with only 3 pins showing. Looks like they can be ordered with digital and analog output, use 5VDC power, and low current requirements.

Can anyone who has used any of these comment on it's sensitivity? Are they pretty reliable?

I've used the one from Sparkfun but looking for something smaller with smaller range.This line of sensors has 2m, 5m and 10m models.

I've also use the parallax one, but I find it is hard to mount and use in a practical manner and it's extremely sensitive and goes off too much for my liking. Sometimes even when there is nothing in front of it.
14  Development / Other Software Development / Re: bootloading with UNO and Arduino as ISP on: January 30, 2011, 03:24:36 pm
According to the site, the UNO can't be used as an ISP yet because of the new optiboot bootloader that the UNO is using.

Quote
NOTE: Currently, you cannot use an Arduino Uno as an ISP programmer because the optiboot bootloader does not support this sketch. A revision for this is in progress.

That quote taken from here: http://arduino.cc/en/Tutorial/ArduinoISP
15  Using Arduino / Project Guidance / Re: Atmega 328 standalone on: January 30, 2011, 08:58:04 am
You'll need more hooked up than just power and ground wires. A 16mhz crystal with 18-22pf capacitors (the actual size of the capacitors you'll need depends on the crystal you get) or a 16mhz resonator, which has the capacitors built in. Resonators sacrifice accuracy in the name of having a smaller size and require fewer components. You'll also need a 10k pullup resistor on the reset pin as well.

Here's a link that will show you the minimum components to get the chip going. After that, attach your other circuits to the pins you were using and you're good to go.
http://arduino.cc/en/Main/Standalone
Pages: [1] 2