Show Posts
Pages: 1 2 [3]
31  Using Arduino / Programming Questions / Re: Errors in code with Capacitive Sensor on: January 02, 2013, 07:22:12 am
What sequence of events do you want to have happen to cause the pin to toggle? A reading below 1100, followed by a reading below 1100, followed by a reading above 1100?
in my test the value that i registreted in my room are from 0 to 1000 ..ok..now what i want to do is when i close the hand to foil (2-3inches,and values reach 1100 or more),make the led1 On,and when i close the hand again make "led1 Off" ...it should be something like
Code:
const int led1 = 13;
const int sensor = cs_4_2.capSense; // i think this is rong

void setup() {
  Serial.begin(9600);
  pinMode(led1, OUTPUT);
}

void loop() {
  static boolean "sensor" = false;
  static boolean LED1value = LOW;

  bool sensorTouch = sensorValue > 1000 && sensorValue <1900;

  if (sensorTouch && !lastSensorTouch)  // Now true, was false
    {
    LED1value = !LED1value; // Toggle the LED1
    digitalWrite(led1, LED1value);
    }
  lastSensorTouch = sensorTouch;
  delay(150);
}

 

now i know this example i rote is rong but the ideea is to get something similar,thank you and excuse me for being so annoyng
32  Using Arduino / Programming Questions / Re: Errors in code with Capacitive Sensor on: January 02, 2013, 06:54:16 am
Hi PaulS i have been testing the capacity and yes you were right the values ramps and variates alot,and there are many factors that makes it unstable,so it took me some time to settingit to the right one,(for ex.if it the arduino board is powersuplied by usb and than change it to 12v Dc,the value passes from 260 to 1200 when you are 2 inches from the foil).Anyway dicided to go further with this i am posting the code that i actually use,with the hope to help me changeing it to a toogle swich
The code below light a led for 2000 milisec when the value is more than 1100

Code:
  #include <CapSense.h>


CapSense   cs_4_2 = CapSense(4,2);         // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add Bare Paint
int ledPin1 = 13;

void setup()                 
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example   
   Serial.begin(9600);
}

void loop()                   
{   
    long start = millis();   
    long total1 =  cs_4_2.capSense(30);   
 
    if (total1 > 1100) {
      digitalWrite(ledPin1, HIGH);  // turn LED1 ON
       delay(2000);
    } else{
      digitalWrite(ledPin1, LOW);  // turn LED1 OFF
 }

Serial.println(total1);   
delay(100);                                         


thank you  again smiley-confuse
33  Using Arduino / Programming Questions / Re: Setting Arduino's date and time? on: January 02, 2013, 06:34:02 am
hi there can i ask a question,the DS1307 RTC have battery backup so it doesnt lose the time...but what about hour change?(when clock turn fwd and bckwd) do i have to change the arduino values allways?or is there any way to do it buy it self..thankyou
34  Using Arduino / Programming Questions / Re: Errors in code with Capacitive Sensor on: December 31, 2012, 01:50:00 am
hi PaulS
thank you for replay,ok the first code is just an example from the web wich display thru the serial values of how close is the hand to the foil,and the second one ..well i tried to make it like a toogle swich,using a swich code from an example,since i am new with the programing i try to keep it the simpliest as posible,and take it in parts,so i can learn...and since i didnt find any other code like the one i need i am asking for clues.thank you

35  Using Arduino / Programming Questions / Re: Errors in code with Capacitive Sensor on: December 30, 2012, 06:18:55 pm
hi everyone,since i have found no answer to my questions and didn"t want to make a new post a hope to find my answer here.
i am triyng to do something similar,like lite a led when capacitive value is higher than 300,the library i used is cap.sense 003 and the code ive tryied is :


#include <CapSense.h>


/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Slightly adapted by Bare Conductive 2011
* Uses a high value resistor e.g. 10 megohm between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin - try different amounts of Bare Paint
* Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
*/


CapSense   cs_4_2 = CapSense(4,2);         // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add Bare Paint

void setup()                 
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example   
   Serial.begin(9600);
}

void loop()                   

{   
long start = millis();   
long total1 =  cs_4_2.capSense(30);   

Serial.println(total1);                                // OPTIONAL: To use additional sensors,change Serial.println to Serial.print for proper window spacing   

delay(100);                                          // arbitrary delay to limit data to serial port
}

 ....ok so this one works great,with the serial id say 300-350 is the perfect value for me.But i tried with a code ive made and something is rong,i want it to act like a toggle swich,here is my code...


#include <CapSense.h>

CapSense   cs_4_2 = CapSense(4,2);         // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin
const int led1 = 13;
const int CapSense


void setup() {               
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example   
   pinMode(led1, OUTPUT);
   Serial.begin(9600);
 }

void loop()  {                 
  static boolean lastSensorTouch = false;
  static boolean LEDvalue = LOW;
 
  long start = millis();   
  long total1 =  cs_4_2.capSense(30);   

 
  int CapSenseValue = read(CapSense)1,0,900);
  bool CapTouch = CapSenseValue > 350 && sensorValue <500;
 
    if (CapTouch && !lastSensorTouch)  // Now true, was false
    {
    LEDvalue = !LEDvalue; // Toggle the LED
    digitalWrite(led1, LEDvalue);
    }
  lastSensorTouch = CapTouch;
 }
 

Serial.println(total1);                         

delay(100); 


anyone have any ideea,il apreciate it,thank you smiley-wink
36  Using Arduino / Interfacing w/ Software on the Computer / Re: momentary switch with Visual Basic on: December 03, 2012, 12:52:59 pm
exactly rbright u need to add to the form a "serialport1"  and one single "button".I will keep postin my next projects with arduino-Vb ..this has a huge potencial..u can do millions of things with it smiley-grin
37  Using Arduino / Interfacing w/ Software on the Computer / Re: momentary switch with Visual Basic on: December 01, 2012, 02:03:30 pm
He He i had a little error but it,s fixed smiley-grin if someone needs the code here it is:


Arduino code :



int ledPin13 = 13;
int ledPin12 = 12;
int dato;

void setup() {
Serial.begin(9600);
pinMode(ledPin13, OUTPUT);
pinMode(ledPin12, OUTPUT);
}

void loop() {

if (Serial.available() > 0) {

dato = Serial.read();

if (dato == '1') {
digitalWrite(ledPin13, HIGH);
}
if (dato == '2') {
digitalWrite(ledPin13, LOW);
}
}
}

------------------------------------------------------->

VB code :

Imports System.IO.Ports
Imports System.Threading

Public Class Form1
    Dim Mypin13 As Boolean = True

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Close()
        SerialPort1.PortName = "com17" 'Chage to your COM
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
    End Sub

    Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        SerialPort1.Open()
        SerialPort1.Write("1")
        SerialPort1.Close()
    End Sub

    Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
        SerialPort1.Open()
        SerialPort1.Write("2")
        SerialPort1.Close()
    End Sub
End Class

...simple isnt it¿ ... trying is the key
thank you again Paul and all of this forum
38  Using Arduino / Interfacing w/ Software on the Computer / Re: momentary switch with Visual Basic on: December 01, 2012, 01:16:19 pm
thank you for reply Paul,you are right,i tried before i post but still cant find the right code...anyway i will keep trying until i get it right.Never lose my hope smiley-grin
39  Using Arduino / Interfacing w/ Software on the Computer / momentary switch with Visual Basic on: December 01, 2012, 12:59:04 pm
hello to everyone,i need your advice..seems stupid but i cant figure out what is the exact code.I want to make a simple aplic. in VB2010 that switch a Led only at the moment mouse click the button.So far i got it working fine like a toogle switch but i wanted to be momentary swich and there is no exemple anyware.The Arduino code (witch i think it showuld be like) is :

int ledPin13 = 13;
int data;

void setup() {
Serial.begin(9600);
pinMode(ledPin13, OUTPUT);
}

void loop() {

if (Serial.available() > 0) {

data = Serial.read();

if (data == '1') {
digitalWrite(ledPin13, HIGH);
} else {
digitalWrite(ledPin13, LOW);
}
}
}


With the MonitorSerial seems to work like i want but i have no clue for the VB
For the VB code i want to start serial comunicacion on Form1_Load and to keep it open until the aplicacion is closed...something like:



Imports System.IO.Ports
Imports System.Threading

Public Class Form1
    Dim cambio13 As Boolean = True

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPort1.Open()
        SerialPort1.PortName = "com17" 'Change port COM
        SerialPort1.BaudRate = 9600
        SerialPort1.DataBits = 8
        SerialPort1.Parity = Parity.None
        SerialPort1.StopBits = StopBits.One
        SerialPort1.Handshake = Handshake.None
        SerialPort1.Encoding = System.Text.Encoding.Default
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SerialPort1.Write("1")
    End Sub

End Class

Thank you,for helping
40  Using Arduino / Sensors / Re: sharp ir switch on: October 18, 2012, 12:46:12 am
work like charm,no debounce and very stable,thank you so much johnwasser,i realy apreciate your help smiley-grin
41  Using Arduino / Sensors / sharp ir switch on: October 17, 2012, 10:52:36 am
hi everyone,after reading allmost all post around here and google,hope 2 get my answers here.I found hundred of examples of Ir conected to Atmegas that light up a Led when get close to object,but not even one example on how to make a toogle switch.Im not the only one looking for codes like this,truth is this subject is avoided,anyway..I wanna do a simple toogle switch,with the arduino Duemilanove and the Sharp 2Y0A21 ir sensor,that can light a Led.So far i can only make it like momentary switch:
+LED on pin 13
+DATA from ir on pin analog 0
----------------------------------
int led1 = 13;
int sensor = A0;
 
void setup() {
  Serial.begin(9600);
  pinMode(led1, OUTPUT);     
}
 
void loop() {
// we read the sensor Value
  int Value = analogRead(A0);
// we maps the value
  int sensorValue = map(Value, 0, 1024, 0 , 200);
// turn on the led1 when the value is beetween 50 and 100
  if ( sensorValue > 50 && sensorValue <300){
    digitalWrite(13, HIGH);
 
  }

  else {
// turn off the two leds
    digitalWrite(13, LOW);
   
  }
  Serial.println(sensorValue);
  delay(100);
}
Pages: 1 2 [3]