Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: delay code on: November 17, 2011, 09:06:09 pm
timer = timer + 1 3000 times is easy for arduino. It is doing it faster than you think.

the serial.print is slowing it down enough to provide enough high time to the led. the duty cycle without serial.print is too small to see the led light most probably.
so if i don't want to use serial.print on my code, how should i do ?
should i put higher value for counter timer variable ?
2  Using Arduino / Programming Questions / Re: delay code on: November 17, 2011, 08:45:04 pm
You've got a watch (millis()) and a pad of paper (the variables you define in the sketch). Now, define how YOU would approach the problem.

Once you know how to perform the actions that you want the Arduino to perform, making the Arduino do it is trivial.


You have three states, right?
1) waiting for trigger
2) triggered, but waiting for a certain point in time
3) triggered, and after the certain point in time

In states 1 and 2, you want your LED to be off.
In state 3, you want your LED to be on.

You could for example, use one variable for what state you're in, and switch on that state in loop().
In state 1, check the trigger, and if it's on, switch to state 2.
Then you could use another variable for when the light should turn on. Set that variable as you switch from state 1 to state 2, and check the time in the loop function for state 2 for whether it's time to switch to state 3.
Turn the LED on when switching to state 3.

sorry,,i didn't follow my thread for a while

actually i've made a sketch for this project
but i'm not using millis() function,,coz still confuse how to  apply millis on my project  smiley-razz
i took another way

here is the code :

Code:
int pirPin = 1;
int ledPin =12;
boolean hold = false;
long timer;

void setup(){
pinMode (pirPin, INPUT);
pinMode (ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
int pirState = digitalRead(pirPin);
if (pirState == HIGH){
digitalWrite(ledPin, HIGH);
hold = true;
timer = 0;
}
else if (hold == true){
timer = timer + 1;
Serial.println(timer);
if (timer > 3000){
digitalWrite(ledPin, LOW);
timer = 0;
hold = false;
     }
   
}
else {
digitalWrite(ledPin, LOW);
 }
}

i'm using counter code in variable timer (timer = timer + 1)
i set 3000 counter for timer
3000 counter doesn't mean 3000ms..when i observed, 3000 counter = 18 sec

when i set additional input & output, the system works parallel well
but the counter orientation is different...when i observed, 3000 counter = 20 sec
why ?

and also i have to put Serial.println on my code
if it did'nt, the timer won't counting




3  Using Arduino / General Electronics / external power for mega-ethernetshield on: October 29, 2011, 04:57:06 am
i'm using arduino mega 1280 connected with ethernet shield..
there are 16 pin occupied as input/output
and i would like to use 12V 5A external switching power supply to run my devices
is it ok ?




4  Using Arduino / Networking, Protocols, and Devices / icsp jumper arduino mega-ethenet shield on: October 07, 2011, 12:41:30 am
i'd like to connect ethernet shield with my arduino mega 1280
i've made a jumper from icsp male connector (arduino mega)to icsp female conector (ethernet shield)
icsp contains : 5 volt, ground, miso, mosi, sck, reset
but it did'nt work when i testing it with my code
did i miss some pin to connect ?
thanks
5  Using Arduino / General Electronics / icsp jumper arduino mega-ethenet shield on: October 06, 2011, 11:39:19 pm
i'd like to connect ethernet shield with my arduino mega 1280
i've made a jumper from icsp male connector (arduino mega)to icsp female conector (ethernet shield)
icsp contains : 5 volt, ground, miso, mosi, sck, reset
but it did'nt work when i testing it with my code
did i miss some pin to connect ?
thanks
6  Using Arduino / Programming Questions / Re: delay code on: September 20, 2011, 04:57:36 am
Don't use "delay", or your program will be "blind" for the duration of the delay.

Have a look at the "blink-without-delay" example in the IDE to see how to do it properly.
yap i knew i shouldn't use "delay".. and i've seen "blink-without-delay" too
but i'm still confuse how to apply "millis" to solve my problem
7  Using Arduino / Programming Questions / delay code on: September 20, 2011, 02:45:32 am
hello everyone
i'm trying to create a simple project about automation. the logic is very simple :if sensor is high then i want the led turning on in a minute
i'd like to put a delay/timer (about a minute) only on the led, so the sensor reading won't be affected with the delay
but i don't know how i should put the delay code
enlighten me please..
thanks before  smiley

Code:
int pirPin = 1;
int ledPin =12;

void setup(){
pinMode (pirPin, INPUT);
pinMode (ledPin, OUTPUT);
}
void loop(){
if (pirPin == HIGH){
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(ledPin, LOW);
}
}
8  Using Arduino / Programming Questions / Re: [ethernet] controlling led with automatic and manual mode on: June 09, 2011, 03:27:10 pm

You're reading from an output pin? Got a poor memory? You should keep track of whether you have turned the light on, or not.
..............

Telling us what you expect, and what actually happens, and how that differs from what you want, is a whole lot more productive.

reading the output pin to ensure the current status of led..

the problem is when the system running on manual mode ("set toggle" pressed),
i want led output doesn't depend on sensor status anymore..

when i press  "set toggle" i want to keep (toggled) the current led pin status. if led current status is HIGH, i want to keep led ON even the sensor reading is LOW...

when i press the "set turn" button, i want led output OFF/ON depends on the current status of led pin (OFF if  led current status pin is HIGH, or ON if led pin current status is LOW)

what actually happens :
it seems led output still depends on sensor status even i pressed "set toggle" button
when i press "set toggle" button, it doesn't keep the current led pin status (except when led current status is LOW)
when i press "set turn"button, it doesn't change led output










9  Using Arduino / Programming Questions / [ethernet] controlling led with automatic and manual mode on: June 09, 2011, 01:14:40 pm
i'm trying to control led in automatic and manual mode.. and make monitoring+controlling system via web using ethernet shield

in automatic mode, the output of led depends on sensor reading
if (sensor HIGH) {then led HIGH} else { then led LOW}

in manual mode, the output led does'nt depend on sensor reading anymore.. but it depends on "set turn" button clicking which is only available when manual mode activated.
to activate the manual mode, the "toggle" button must be clicked first..if the "toggleoff" button clicked, that would set back to automatic mode

well..the automatic mode is fine..  the problem is the manual mode.. it still does'nt work
here is my code.. please check it out.. which part is wrong ?
thanks

Code:
#include <SPI.h> 
#include <Ethernet.h>


byte mac[] = { 0x54, 0x55, 0x58, 0x10, 0x00, 0x24 };  //  MAC
byte ip[]  = { 167, 205, 45, 177 };                  // IP-Adress
byte gateway[] = { 167, 205, 1, 1 };                // Gateway
byte subnet[]  = { 255, 255, 255, 0 };

Server server(80);
int Pir1 = 2;  //sensor pir
int Led1 = 12;  //  led output
boolean Pir1ON, Led1ON, Toggle1ON = false;
int PirState1 = 0;

String readString = String(100);      // string for fetching data from address

void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
 
pinMode(Pir1, INPUT);
pinMode(Led1, OUTPUT);
 }

void loop(){
int PirState1 =digitalRead(Pir1); //reading pir sensor status
int LedState1 = digitalRead(Led1); // reading led status

// automatic mode

if(PirState1 == HIGH){ 
  Pir1ON = true;
 digitalWrite(Led1, HIGH);
 }
  else{
    Pir1ON = false;
        digitalWrite(Led1, LOW);
}

 if(LedState1 == HIGH){
 Led1ON = true;
 }
 else{
   Led1ON = false;
 }

// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string

readString = readString + c;

}

Serial.print(c);  //output chars to serial port

if (c == '\n') {  //if HTTP request has ended


// manual mode when "toggle" button pressed
//maybe this part is the problem

if(readString.indexOf("1=set+toggle") > -1) {
  Toggle1ON= true;
  if(LedState1 == HIGH){
  if(readString.indexOf("1=set+turn") > -1) {
    digitalWrite( Led1, LOW);
    Led1ON = false;
   }} else {
      if(readString.indexOf("1=set+turn") > -1) {
    digitalWrite( Led1, HIGH);
    Led1ON = true;
  }
   }
}

// ended manual mode   
if(readString.indexOf("1=toggleoff") > -1){
  Toggle1ON= false;
}

//--------------------------HTML------------------------
client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println();

client.print("<html><head>");

client.print("<title>Arduino Webserver </title>");
client.println("<meta http-equiv=\"refresh\" content=\"2\">");

client.println("</head>");

client.print("<body bgcolor='white'>");


client.println("<br><hr />");

client.println("<h1><div align='center'><font color='#2076CD'>Arduino Webserver</font color></div></h1>");


client.println("<div align='center'>");
client.println("<table border=5>");

// display manual mode (when "toggle" button pressed)
if(Toggle1ON){
  if(Pir1ON){   
client.println("<tr>");
client.println("<td bgcolor='red'>Sensor 1</td> <td bgcolor='yellow'>ON</td>");
if(Led1ON){
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='yellow'>ON</td>");
  }
  else{
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='red'>OFF</td>");
 }
 client.println("<td align='middle'><form method=get><input type=submit name=1 value='set turn'></form></td><td align='middle'><form method=get><input type=submit name=1 value='toggleoff'></form></td>");
 client.println("</tr>");
}
else{
  client.println("<tr>");
  client.println("<td bgcolor='white'>Sensor 1</td><td bgcolor='red'>OFF</td><td bgcolor='white'>Led 1</td> <td bgcolor='red'>OFF</td><td align='middle'><form method=get><input type=submit name=1 value='set turn'><td align='middle'><form method=get><input type=submit name=1 value='toggleoff'></form></td>");
  client.println("</tr>");
  }
}

// display automatic mode
else{
if(Pir1ON){   
client.println("<tr>");
client.println("<td bgcolor='red'>Sensor 1</td> <td bgcolor='yellow'>ON</td>");
if(Led1ON){
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='yellow'>ON</td>");
    }
  else {
  client.println("<td bgcolor='white'>Led 1</td> <td bgcolor='red'>OFF</td>");
 }
 client.println("<td>set turn</td><td align='center'><form method=get><input type=submit name=1 value='set toggle'></form></td>");
 client.println("</tr>");
}
else{
  client.println("<tr>");
  client.println("<td bgcolor='white'>Sensor 1</td><td bgcolor='red'>OFF</td><td bgcolor='white'>Led 1</td><td bgcolor='red'>OFF</td> <td align='center'>set turn</td> <td align='center'><form method=get><input type=submit name=1 value='set toggle'></form></td>");
  client.println("</tr>");
  }
}


client.println("</table>");
client.println("</div>");

client.println("</body></html>");

//clearing string for next read
readString="";

//stopping client
delay(1);
client.stop();
}}}}

}
10  Using Arduino / Programming Questions / Re: [ethernet] making a table with 'for' function on: June 06, 2011, 11:33:40 am
wow thanks for the responses
really help me a lot
11  Using Arduino / Programming Questions / [ethernet] making a table with 'for' function on: June 06, 2011, 09:18:53 am
hi guys
i'm still struggling with my arduino+ethernet programming codes
i'm trying make a table like this on my webserver project :

   | Sensor 1| Off | LED 1| Off |
   | Sensor 2| Off | LED 2| Off |
   | Sensor 3| Off | LED 3| Off |
   | Sensor 4| Off | LED 4| Off |

i tried "for" function in my codes.. but it still doesnt work
here is my code :

........................

client.println("<table>");
for (int i=1;i<=4;i++){
client.println(<tr>");
clint.println("<td>Sensor (+i+)</td><td> Off </td><td>LED (i)</td><td>OFF</td>");
client.println("</tr>");
}
client.println("<table>");

..........................................

the result is :

   | Sensor (+i+)| Off | LED (+i+)| Off |
   | Sensor (+i+)| Off | LED (+i+)| Off |
   | Sensor (+i+)| Off | LED (+i+)| Off |
   | Sensor (+i+)| Off | LED (+i+)| Off |

 
i dont know how to turn "(+i+)" into 1,2,3,4
please help me, i'm a newbie
thanks


   
12  Using Arduino / Programming Questions / Re: [ethernet] updating pin status on webpage without refresh on: June 03, 2011, 08:16:29 pm
ok it works
thanks..really appreciate that smiley-grin
13  Using Arduino / Programming Questions / [ethernet] updating pin status on webpage without refresh on: June 03, 2011, 01:22:22 pm
hey guys..
i'm a newbie using arduino mega and ethernet shield..i use the ethernet shield as a webserver
i'm trying to read a pin status (digital)..and write it on the web pages (if pin status is high, then write "ON" on the webpage..else write"OFF")
my problem is the status pin ("ON" or "OFF") on the webpage does'nt change until i refresh the webpage
i want the webpage load the current status without pressing the refresh button
what should i do with my codes?
thanks
14  Community / Local Groups / Re: Indonesia / Jakarta anyone?? on: May 22, 2011, 05:25:20 am
hi, apa kabar?
i am an Arduino user from Jakarta, Indonesia. looking for my fellow Indonesian to join..
hi i'm from bandung.. glad to find you here.. i'm a newbie on this forum smiley-grin

Hi! Am new here too! I dont have a arduino board yet. I want to buy! where can i get one in Jakarta?

i bought arduino from geraicerdas.com (based in jakarta) two months ago
you can also check famosastudio.com .. both are official arduino distributor in indonesia


Pages: [1]