Posted on

ESP8266 Write Multiple Fields Thingspeak.com

ESP8266 Write Multiple Fields Thingspeak.com

 

#include <ESP8266WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h" // include thingspeak header
#include <math.h>

char ssid[] = SECRET_SSID;   // your network SSID (name) 
char pass[] = SECRET_PASS;   // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)
WiFiClient  client;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

// Schematic:
// [+3V] ---- [Thermistor 10k-Resistor] -------|------- [10k-Resistor] ---- [Ground]
//                                             |
//                                       Analog Pin A0

int analogpin = A0; 
int sensorvalue; 
float Vin;
float Temp_C;  // Celsius
float Temp_K;  // Kelvin
float Temp_F;  // Fahrenheit

//*****************************************************************************************************
float Thermistor(int RawADC){ //Function to perform math of the Steinhart-Hart equation
  
      Temp_C = log(((10230000/RawADC)-10000));       // Temp = log(10000.0*((1023.0/RawADC-1)));
      Temp_C = 1/(0.001129148+(0.000234125+(0.0000000876741*Temp_C*Temp_C))*Temp_C);
      Temp_C = Temp_C - 273.15;                       // Convert Kelvin to Celsius
      return Temp_C;
}

//*****************************************************************************************************
// Initialize values
int number1 = 0;
int number2 = 0;
int number3 = 0;
int number4 = 0;
String myStatus = "";

//*****************************************************************************************************
void setup() {
  Serial.begin(115200);  // Initialize serial
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo native USB port only
  }
  WiFi.mode(WIFI_STA); 
  ThingSpeak.begin(client);  // Initialize ThingSpeak
}

//*****************************************************************************************************
void loop() {
  // Connect or reconnect to WiFi
  if(WiFi.status() != WL_CONNECTED){
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(SECRET_SSID);
    while(WiFi.status() != WL_CONNECTED){
      WiFi.begin(ssid, pass);  // Connect to WPA/WPA2 network. Change this line if using open or WEP network
      Serial.print(".");
      delay(5000);     
    } 
    Serial.println("\nConnected.");
  }
  
//****************************************************************************************************
    Vin = sensorvalue*(3.0/1023.0);  

    sensorvalue = analogRead(analogpin);
    Temp_C = Thermistor(sensorvalue);       // Temp_C = Thermistor(analogRead(analogpin));
    
    Temp_K = Temp_C + 273.15;             // Convert Kelvin  to Celcius
    Temp_F = (Temp_C*1.8) + 32.0;          // Convert Celsius  to Fahrenheit


    Serial.print("ADC Sensor Value\t");
    Serial.print(sensorvalue); 
    Serial.print("\t");
    
    Serial.print("Voltage input\t");  
    Serial.print(Vin); 
    Serial.print("\t");
    
    Serial.print("Temperature Celsius\t");     
    Serial.print(Temp_C); 
    Serial.print("\t");

    Serial.print("Temperature Kelvin\t");        
    Serial.print(Temp_K); 
    Serial.print("\t");

    Serial.print("Temperature Fahrenheit\t");        
    Serial.print(Temp_F); 
    Serial.println("\t");   

    
  number1 = sensorvalue;
  number2 = Vin;
  number3 = Temp_C;
  number4 = Temp_K;
  
//****************************************************************************************************    
// set the fields with the values
  ThingSpeak.setField(1, number1);
  ThingSpeak.setField(2, number2);
  ThingSpeak.setField(3, number3);
  ThingSpeak.setField(4, number4);
  
 //****************************************************************************************************    
  // figure out the status message
  if(number1 > number2){
    myStatus = String("field1 is greater than field2"); 
  }
  else if(number1 < number2){
    myStatus = String("field1 is less than field2");
  }
  else{
    myStatus = String("field1 equals field2");
  }
 //****************************************************************************************************    
  // set the status
  ThingSpeak.setStatus(myStatus);
 //****************************************************************************************************    
 // write to the ThingSpeak channel
  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  if(x == 200){
    Serial.println("Channel update successful.");
  }
  else{
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }
  
 //****************************************************************************************************    
  delay(5000); // Wait 5 seconds to update the channel again
 //****************************************************************************************************    
}

 

Channel update successful.
ADC Sensor Value 585 Voltage input 1.72 Temperature Celsius 31.73 Temperature Kelvin 304.88 Temperature Fahrenheit 89.11
Problem updating channel. HTTP error code -401

https://thingspeak.com/channels/1452499

 

 

Posted on

แผ่นสะท้อนแสงโฟโตอิเล็กทริคเซนเซอร์ Photoelectric Sensor Reflectors Plate

แผ่นสะท้อนแสง/แผ่นสะท้อนแสง สำหรับเซ็นเซอร์สวิตช์ photoelectric switch sensor ใช้เซ็นเซอร์สะท้อนแสงแบบโพลาไรซ์ รีเฟลกเตอร์ทรงลูกบาศก์มุม

Posted on

วัดอุณหภูมิด้วยเทอร์โมคัปเปิล Thermocouple Type K MAX6675

วัดอุณหภูมิด้วยเทอร์โมคัปเปิล Thermocouple Type K MAX6675

  • Thermocouple Type K สามารถวัดอุณหภูมิในช่าง 0-800 C
  • MAX6675 ตัวแปลง K-Thermocoupleto 0°C ถึง +1024°C เป็น Digital ข้อมูล
    เป็นเอาต์พุตในความละเอียด 12 บิต รองรับ การสื่อสาร SPI
  • https://datasheets.maximintegrated.com/en/ds/MAX6675.pdf

การติดตั้ง Library 

 

 

การเปิดตัวอย่างโค้ด 

/*
  Average Thermocouple

  Reads a temperature from a thermocouple based
  on the MAX6675 driver and displays it in the default Serial.

  https://github.com/YuriiSalimov/MAX6675_Thermocouple

  Created by Yurii Salimov, May, 2019.
  Released into the public domain.
*/
#include <Thermocouple.h>
#include <MAX6675_Thermocouple.h>

#define SCK_PIN 3
#define CS_PIN 4
#define SO_PIN 5

Thermocouple* thermocouple;

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);

  thermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
}

// the loop function runs over and over again forever
void loop() {
  // Reads temperature
  const double celsius = thermocouple->readCelsius();
  const double kelvin = thermocouple->readKelvin();
  const double fahrenheit = thermocouple->readFahrenheit();

  // Output of information
  Serial.print("Temperature: ");
  Serial.print(celsius);
  Serial.print(" C, ");
  Serial.print(kelvin);
  Serial.print(" K, ");
  Serial.print(fahrenheit);
  Serial.println(" F");

  delay(500); // optionally, only to delay the output of information in the example.
}

 

Posted on

ROS

ROS build is based on Linux version: Ubuntu 16.04 LTS install a virtual machine and Linux operating system

Install Linux Inside Windows Using VirtualBox

Step 1: Download and install VirtualBox

https://www.virtualbox.org/wiki/Downloads

Step 2: Download the Linux ISO
https://ubuntu.com/download/desktop

Step 3: Install Linux using VirtualBox

ROS basis

Posted on

PLC เบื้องต้น

PLC เบื้องต้น Programmable logic controller การเขียนโปรแกรม (Programming) หรือ การเขียนโค้ด (Coding)  PLC เบื้องต้น นั้นใช้ ภาษา Ladderภาษาที่ใช้ในการเขียนโปรแกรม PLC คำสั่งบูลีน

 

Interlocks

START       STOP                     OUT
----| |----+----| |----------------------( )
           |
   OUT     |
----| |----+

 

Posted on

เริ่มต้นใช้งานระบบ DAQ อย่างง่ายโดยใช้ parallax.com PLX-DAQ Excel & Arduino from