Hi, I hope you can help me with my project, I am working with a coin slot and I managed to monitored the inserted coins in my Serial Monitor but I have a problem on how to transfer the data to a PHP localhost. I hope you can help me. Thanks.
Here's the Arduino Code:
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);
// Constants
const int coinpin = 2;
const int ledpin = 8;
// Variables
volatile int pulse = 0;
volatile unsigned long timelastPulse = 0;
boolean bInserted = false;
int credits = 0;i
nt price = 20;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192, 168, 1, 11 }; //Enter the IP of ethernet shield
byte serv[] = {192, 168, 1, 10} ; //Enter the IPv4 address
EthernetClient cliente;
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.backlight;
lcd.clear();
Ethernet.begin(mac, ip);
attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
displayCredit();
}
void loop() {
unsigned long lastTime = millis() - timelastPulse;
if( (pulse > 0 ) && ( lastTime > 200) ){ // for show LED ON when Inserted
bInserted = false;
credits += pulse;
pulse = 0;
displayCredit();
}
if( credits >= price ){
digitalWrite(ledpin, HIGH);
}
if (cliente.connect(serv, 80)) { //Connecting at the IP address and port we saved before
Serial.println("connected");
cliente.print("GET /sample/data.php?"); //Connecting and Sending values to database
cliente.print("Coins Inserted:");
cliente.print(credits);
cliente.stop(); //Closing the connection
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(5000);
}
void coinInterrupt(){
// Each time a pulse is sent from the coin acceptor,
// interrupt main loop to add 1 and flip on the LED
pulse++ ;
timelastPulse = millis();
// digitalWrite(ledpin, HIGH);
// Serial.println( pulse );
}
void displayCredit()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Credit:");
lcd.setCursor(0,1);
lcd.print( credits );
}
Now here's My PHP code named data.php I haven't figured how can it receive the data from arduino
Coins Inserted:
<p value="<?php $row['credits'] ?> </p> </body> </html> <p>Hope you can help me guys I am trying my best and still can't get the results that I wanted. Thanks.</p>